﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AlgoImpl.ConverterAnalyzer;

namespace AlgoImpl
{
    public abstract class StepManagerAbstract
    {
        protected ShiftRequests MRequests;
        protected Converter m_Converter;
        protected AnalyzerManager m_AnalyzerMgr;
        protected AlgoExecuter m_AlgoExecuter;
        protected int m_NumOfIterations;
        protected int m_CurrIteration;

        public AnalyzerManager AnalyzerMgr 
        {
            get { return m_AnalyzerMgr; }
            set { m_AnalyzerMgr = value; } 
        }

        public virtual void RunStep()
        {
            m_CurrIteration = 1;
            for (int i = 0; i < m_NumOfIterations; i++)
            {
                preperations();
                convertToGraph();
                runAlgo();
                analyzeResults();
                m_CurrIteration++;
            }
            finalize();
        }

        protected abstract void preperations();
        protected abstract void finalize();
        protected abstract void analyzeResults();
        protected abstract void runAlgo();
        protected abstract void convertToGraph();

        protected  List<string> getAllWorkers()
        {
            return SharedData.Instance.GetAllWorkersIds();
        }

        protected  List<string> getAllShifts()
        {
            return SharedData.Instance.GetAllShiftsIds();
        }

        protected void updateGlobalResultData(eStepThatGotShift step)
        {
            foreach (string workerId in getAllWorkers())
            {
                foreach (string shiftId in getAllShifts())
                {
                    if (SharedData.Instance.GetWorkerById(workerId).IsRegisterdToShift(shiftId))
                    {
                        if (!FinalResultHolder.Instance.IsShiftSetForWorker(workerId, shiftId))
                        {
                            ShiftResult result = new ShiftResult(shiftId, step);
                            FinalResultHolder.Instance.AddShiftResultToWorkerList(workerId, result);
                        }
                    }
                }
            }
        }


    }
}
